import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:yuan_hang_app/res/w_colors.dart';
import 'package:yuan_hang_app/utils/size_utils.dart';
import 'package:yuan_hang_app/widget/w_text.dart';

class WLoading extends StatefulWidget {
  final double width;
  final double height;
  final double loadingWidth;
  final String? bgName;
  final Color loadingColor;
  final String hintText;

  const WLoading(
      {super.key,
      this.bgName = "ic_loading.png",
      this.width = 40,
      this.height = 40,
      this.loadingWidth = 40,
      this.loadingColor = WColors.white,
      this.hintText = "努力加载中..."});

  @override
  State<StatefulWidget> createState() => _LoadingState();
}

class _LoadingState extends State<WLoading>
    with SingleTickerProviderStateMixin {
  late AnimationController controller;

  @override
  void initState() {
    super.initState();
    controller = AnimationController(
        duration: const Duration(milliseconds: 800), vsync: this);
    controller.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        controller.reset();
        controller.forward();
      }
    });
    controller.forward();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return RotationTransition(
      alignment: Alignment.center,
      turns: controller,
      child: Image.asset(
        'images/${widget.bgName}',
        color: widget.loadingColor,
        width: widget.loadingWidth,
      ),
    );
  }
}
